package com.example.administrator.basedemos.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.basedemos.R;
import com.example.administrator.basedemos.activity.OptinalEdtActivity;
import com.example.administrator.basedemos.activity.OptionalAddActivity;

import java.util.ArrayList;

/**
 * 创建者     ZCL
 * 创建时间   2018/7/4 11:57
 * 描述	      ${自选模块}
 * <p>
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */
public class OptionalFragment extends BaseMarketFragment implements View.OnClickListener {

    private TextView mEdt;
    private View     mAdd;
    private ArrayList<String> mList;

    @Override
    public void setAboutAdapter() {
        setEmptyView(R.layout.empty_optional_view);
        View footView = View.inflate(getContext(), R.layout.optional_footer, null);
        mEdt = footView.findViewById(R.id.optional_edt);
        mAdd = footView.findViewById(R.id.optional_add);
        mAdapter.addFooterView(footView);
    }

    @Override
    public ArrayList<String> setData() {
        mList = new ArrayList<>();
        mList.add("1");
        mList.add("1");
        mList.add("1");
        return mList;
    }

    @Override
    protected ArrayList loadData(int type) {
        return null;
    }

    @Override
    protected ArrayList refreshData() {
        mList = new ArrayList<>();
        mList.add("1r");
        mList.add("2r");
        mList.add("3r");
        return mList;
    }


    @Override
    protected Bundle setBundle(Bundle bundle, int position) {
        bundle.putString("title",mList.get(position));
        return bundle;
    }

    @Override
    public void initListener() {
        super.initListener();
        View emptyView = mAdapter.getEmptyView();
        emptyView.setOnClickListener(v -> {
            Toast.makeText(getActivity(), "点击空界面", Toast.LENGTH_SHORT).show();
        });
        mEdt.setOnClickListener(this);
        mAdd.setOnClickListener(this);
        mSmartRefresh.setEnableLoadMore(false);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.optional_edt:
                Toast.makeText(getContext(), "编辑自选", Toast.LENGTH_SHORT).show();
                Intent intentAdd = new Intent(getActivity(), OptinalEdtActivity.class);
                startActivity(intentAdd);
                break;
            case R.id.optional_add:
                Toast.makeText(getContext(), "添加自选", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(getContext(), OptionalAddActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }
}
